class Solution:
    def reorderedPowerOf2(self, n: int) -> bool:
        def n2id(number):
            out = [0] * 10

            for a in str(number):
                out[int(a)] += 1

            return tuple(out)

        # ids=set()
        # i=1
        # while i<=10**9:
        #     ids.add(n2id(i))
        #     i*=2
        # print(ids)
        ids = {(1, 1, 0, 0, 1, 0, 2, 1, 2, 0), (0, 0, 1, 3, 2, 2, 0, 0, 0, 0),
               (0, 1, 0, 1, 1, 0, 1, 0, 1, 0), (1, 0, 0, 0, 1, 0, 1, 0, 0, 1),
               (0, 0, 0, 0, 1, 0, 1, 0, 0, 0), (1, 1, 0, 1, 3, 0, 0, 0, 0, 1),
               (1, 0, 0, 1, 0, 0, 1, 0, 4, 0), (0, 0, 0, 1, 0, 2, 2, 0, 0, 0),
               (0, 0, 0, 0, 1, 0, 0, 0, 0, 0), (0, 2, 2, 1, 1, 0, 0, 2, 1, 0),
               (1, 1, 0, 0, 1, 1, 1, 1, 1, 0), (0, 1, 1, 0, 0, 1, 0, 0, 0, 0),
               (1, 1, 2, 0, 0, 1, 0, 1, 0, 1), (0, 2, 1, 0, 0, 0, 2, 3, 0, 0),
               (0, 0, 1, 1, 0, 0, 0, 0, 0, 0), (0, 0, 1, 0, 0, 1, 1, 0, 0, 0),
               (0, 1, 0, 0, 0, 0, 1, 0, 0, 0), (1, 1, 1, 1, 0, 1, 1, 1, 1, 1),
               (0, 1, 1, 0, 0, 0, 0, 0, 1, 1), (1, 2, 1, 1, 0, 0, 0, 1, 0, 0),
               (0, 1, 2, 0, 2, 0, 1, 0, 0, 0), (0, 0, 1, 0, 0, 0, 0, 0, 0, 0),
               (0, 0, 2, 0, 1, 1, 0, 0, 2, 0), (0, 0, 1, 1, 2, 2, 2, 0, 1, 0),
               (0, 1, 0, 0, 0, 0, 0, 0, 0, 0), (1, 1, 1, 0, 1, 0, 0, 0, 0, 0),
               (0, 0, 0, 0, 0, 0, 0, 0, 1, 0), (0, 0, 1, 1, 0, 0, 1, 1, 1, 0),
               (1, 0, 1, 0, 1, 0, 0, 0, 1, 0), (0, 1, 1, 0, 0, 0, 0, 0, 1, 0)}

        if n2id(n) in ids:
            return True

        return False


n = 1
n = 10
n = 16
n = 46
print(Solution().reorderedPowerOf2(n))
